package com.hackvan2012.controllers.ajax;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hackvan2012.api.YellowAPIService;

public class RestaurantSuggestController extends HttpServlet {
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp) {
		boolean sandbox = req.getParameter("sandbox").equals("true"); 
		YellowAPIService ys = new YellowAPIService(req.getParameterMap(), sandbox);
		String result = ys.call();
		result = result.replaceAll("\\[\\]", "");
		String[] resultArray = result.split(",");
		String out ="";
		for(String s : resultArray){			
			String split[] = s.split(":");
			if(split.length >= 2) {
			String tmp = split[1];
			tmp = tmp.replaceAll("[^a-zA-z0-9 ]", "");
			out += tmp+"\n";
			}
		}
		out = out.replaceAll("\\]null", "");
		try {
//			resp.setContentType("text/xml");
			resp.getWriter().write(out);
		} catch (Exception e) {
		}
	}
}
